/*
 ------------------------------------------------------------------------------
	willy-player - a simple music player based on SDL.

	Copyright (C) 2011 Pierre Veber
	
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software Foundation,
	Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
------------------------------------------------------------------------------
*/

#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#define usleep(x)	Sleep((DWORD)(x/1000))
#include "win32/targetver.h"
#include <windows.h>

#else

#define _strdup strdup
#define _strndup strndup
#define _stricmp stricmp

#endif

/*
 ----------------------------------------------------------------------------
	Debug
 ----------------------------------------------------------------------------
*/
void _wp_output_debug(char* lpszString);

/*
 ----------------------------------------------------------------------------
	Path utilities
 ----------------------------------------------------------------------------
*/

int _path_is_dir(const char* pszPath);
int _path_exists(char* path);

/* const pointers: pointers on same string */
const char* _path_find_extension(const char* pszPath);
const char* _path_find_filename(const char* pszPath);

/* not const pointers: pointers on new strings (to be freed) */
char* _path_append(char* pszPath, char* pszMore);
char* _path_find_dir(const char* pszPath);
char* _path_extract_subfolder(const char* pszRoot, const char* pszPath);

/* walk into a directory recursively */
typedef int (*FoundFileProc)(void*, char*, char*);
typedef void* (*MallocProc)(size_t, void*);
int _walk(char* pszBase, void* pData, FoundFileProc fpf, MallocProc fpm);

/*
 ----------------------------------------------------------------------------
	Storage utilities
 ----------------------------------------------------------------------------
*/
char* _wp_user_store();

/*
 ----------------------------------------------------------------------------
	Config utilities
 ----------------------------------------------------------------------------
*/
char* _wp_conf_read(char* pszConfFile, char* pszSection, char* pszKey);
int _wp_conf_write(char* pszConfFile, char* pszSection, char* pszKey, char* pszValue);

/*
 ----------------------------------------------------------------------------
	Instance utilities
 ----------------------------------------------------------------------------
*/
int _wp_init_instance(void);
int _wp_signal_instance(char*);
int _wp_listen_instance(void);
char* _wp_lock_instance_data(void);
int _wp_release_instance_data(void);
int _wp_free_instance_data(void);
int _wp_terminate_instance(void);

/*
 ----------------------------------------------------------------------------
	extern entry point to be called within platform code.
 ----------------------------------------------------------------------------
*/
int _wp_main(char* cmdline);
